//
//  MyDiscountHeaderView.m
//  Findif
//
//  Created by Mac on 2019/4/2.
//  Copyright © 2019年 Cicel Chen. All rights reserved.
//

#import "MyDiscountHeaderView.h"

@interface MyDiscountHeaderView ()

@property (nonatomic, weak)UIButton * moreButton;
@property (nonatomic, weak)UIImageView * rightImageView;

@end

@implementation MyDiscountHeaderView

- (instancetype)initWithReuseIdentifier:(NSString *)reuseIdentifier
{
    if (self = [super initWithReuseIdentifier:reuseIdentifier]) {
        
        [self setupUI];
    }
    return self;
}

- (void)setupUI{
    
    UILabel * titleLabel = [UILabel new];
    
    titleLabel.textColor = ZRBlackColor;
    titleLabel.font = [UIFont boldSystemFontOfSize:15 * SCREENH6];
    
    self.titleLabel = titleLabel;
    
    [self addSubview:self.titleLabel];
    
    
    UIButton * moreButton = [UIButton new];
    
    [moreButton addTarget:self action:@selector(clickMoreButton) forControlEvents:UIControlEventTouchUpInside];
    [moreButton setTitle:@"查看更多" forState:UIControlStateNormal];
    [moreButton setTitleColor:[UIColor lightGrayColor] forState:UIControlStateNormal];
    moreButton.titleLabel.font = [UIFont systemFontOfSize:13 * SCREENH6];
    
    self.moreButton = moreButton;
    
    [self addSubview:self.moreButton];
    
    
    UIImageView * rightImageView = [UIImageView new];
    
    rightImageView.image = [UIImage imageNamed:@"查看更多"];
    
    self.rightImageView = rightImageView;

    [self addSubview:self.rightImageView];
}


- (void)layoutSubviews{
    
    [self.titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.leading.mas_equalTo(self).offset(15 * SCREENH6);
        make.centerY.mas_equalTo(self);
    }];
    
    [self.rightImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.trailing.mas_equalTo(self).offset(-15 * SCREENH6);
        make.centerY.mas_equalTo(self);
        make.width.mas_equalTo(7 * SCREENH6);
        make.height.mas_equalTo(13 * SCREENH6);
    }];
    
    [self.moreButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.trailing.mas_equalTo(self.rightImageView.mas_leading).offset(-3 * SCREENH6);
        make.centerY.mas_equalTo(self);
    }];
}


- (void)clickMoreButton{
    
    if (self.delegate && [self.delegate respondsToSelector:@selector(clickMoreButton:)])
    {
        [self.delegate clickMoreButton:self.titleLabel.text];
    }
}

@end
